#!/usr/bin/env python

from optparse import OptionParser
from os import makedirs
from os.path import dirname, isdir, join

from util import (
    VERSION,
    getResourcesDirectory,
    getTemplatesDirectory,
    writeTemplate
)

def main():
    parser = OptionParser("usage: %prog [options] includeDir libDir")
    parser.add_option("-d", "--destination", action="store",
                      default=join(getResourcesDirectory(), "synthclone.pc"),
                      dest="destination", help="File to write pkgconfig to")
    options, args = parser.parse_args()
    if len(args) != 2:
        parser.error("incorrect number of required arguments")
    pkgconfigFile = options.destination
    pkgconfigDir = dirname(pkgconfigFile)
    if not isdir(pkgconfigDir):
        makedirs(pkgconfigDir)
    data = {
        "includeDir": args[0],
        "libDir": args[1],
        "version": VERSION
    }
    writeTemplate(pkgconfigFile, join(getTemplatesDirectory(), "synthclone.pc"),
                  data)

if __name__ == "__main__":
    main()
